﻿namespace NPSoft.Ferrero.Framework.Utility
{
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Configuration;
    using System.Linq;
    using System.Text;
    using System.Web.Services.Protocols;

    public class NPSoapHeader : SoapHeader
    {
        /// <summary>
        /// 
        /// </summary>
        public NPSoapHeader()
        {
        }

        /// <summary>
        /// 密钥值
        /// </summary>
        public string Key
        {
            get
            {
                NameValueCollection nvc = (NameValueCollection)ConfigurationManager.GetSection("NewsPage/mail");
                string encryptKey = nvc.Get("licenseKey");
                return encryptKey;
            }
        }

        /// <summary>
        /// 验证用户是否有权访问内部接口
        /// </summary>
        /// <param name="key"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool isValid(string key, out string msg)
        {
            msg = "";
            string decryptKey = EncryptHelper.DesEncrypt(key);
            if (Key == decryptKey)
            {
                return true;
            }
            else
            {
                msg = "抱歉，您无权调用此服务！";
                return false;
            }
        }
    }
}
